package com.ehsy.statement;

import com.ehsy.common.ResponseVo;
import com.ehsy.model.UserInfo;
import com.ehsy.service.LogService;
import com.ehsy.service.UrlParamService;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author YanZhen_Li
 * @version 1.0
 * @title A15日志管理
 * @description
 * @create 2024/6/19 9:38
 */
@SpringBootTest
        (webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
                properties = {"spring.config.location=classpath:forest-log.yml"})
public class A15日志管理 {
    @Resource
    UrlParamService service;

    @Resource
    LogService logService;

    /**
     * 统一日志管理
     */
    @Test
    public void test1() {
        ResponseVo<Object> test1 = service.send1("a", "b");
        ResponseVo<Object> test2 = service.send2("a", "b");
        ResponseVo<Object> test3 = service.send3("a=a&b=b");
        ResponseVo<Object> test4 = service.send4("a", "b");
        Map<String, Object> params = new HashMap<String,Object>(){{
            put("a", "a");
            put("b", "b");
            put("id", 0);
            put("c", "c");
            put("d", "d");
        }};
        ResponseVo<Map<String, Object>> test5 = service.send5(params);
        UserInfo userInfo = new UserInfo("张三", "18", "男", "上海", "13812341234", "123@qq.com", "123456");
        ResponseVo<UserInfo> test6 = service.send6(userInfo);
        System.out.println("---------------------------------------");
        System.out.println(test1.getData());
        System.out.println(test2.getData());
        System.out.println(test3.getData());
        System.out.println(test4.getData());
        System.out.println(test5.getData());
        System.out.println(test6.getData());
    }

    /**
     * 单独设置某个接口请求的日志打印
     */
    @Test
    public void test2() {
        UserInfo user = new UserInfo("张三", "18", "男", "上海", "13812341234", "123@qq.com", "123456");
        ResponseVo<UserInfo> test1 = logService.test1(user);
        ResponseVo<UserInfo> test2 = logService.test2(user);
        ResponseVo<UserInfo> test3 = logService.test3(user);

        System.out.println("---------------------------------------");
        System.out.println(test1);
        System.out.println(test2);
        System.out.println(test3);
    }

    /**
     * 如果我们对日志的打印格式不满意，我们可以使用自定义日志处理器来打印想要的日志效果
     * ! 在我们的yml文件中放开全局日志处理器配置项
     */
    @Test
    public void test3() {
        UserInfo user = new UserInfo("张三", "18", "男", "上海", "13812341234", "123@qq.com", "123456");
        ResponseVo<UserInfo> test3 = logService.test3(user);
        System.out.println("---------------------------------------");
        System.out.println(test3);
    }

    /**
     * 配置单个请求的日志处理器，我们可以为某个接口的日志做一个专门的特殊处理
     */
    @Test
    public void test4() {
        UserInfo user = new UserInfo("张三", "18", "男", "上海", "13812341234", "123@qq.com", "123456");
        ResponseVo<UserInfo> test4 = logService.test4(user);
        System.out.println("---------------------------------------");
        System.out.println(test4);
    }

}
